from time import sleep
from selenium import webdriver

# driver = webdriver.Chrome()
from selenium.webdriver.firefox.webdriver import WebDriver

driver = webdriver.Firefox()  # type: WebDriver
driver.get('https://www.baidu.com')
handle_hao123 = driver.current_window_handle
driver.find_element_by_id('kw').send_keys('163邮箱')
# driver.get('https://mail.163.com/')
driver.find_element_by_id('su').click()
sleep(1)
driver.find_element_by_xpath('/html/body/div/div[3]/div[1]/div[3]/div[1]/h3/a').click()
sleep(1)
hds = driver.window_handles
driver.switch_to.window(hds[1])
sleep(1)
iframe = driver.find_element_by_xpath('//div[@id="loginDiv"]/iframe')
# iframe = driver.find_element_by_xpath('//*[@id="x-URS-iframe1592632891026.35"]')
driver.switch_to.frame(iframe)
sleep(1)
driver.find_element_by_name("email").send_keys('***')
driver.find_element_by_name("password").send_keys('***')
driver.find_element_by_id('dologin').click()
sleep(2)
# driver.switch_to_default_content()
driver.switch_to.default_content()
driver.find_elements_by_class_name("oz0")[1].click()
sleep(1)
# driver.find_element_by_id('_mail_component_24_24').click()
driver.find_element_by_class_name('nui-editableAddr-ipt').send_keys('ma_linpop@163.com')
driver.find_elements_by_class_name('nui-ipt-input')[2].send_keys('化工学院_计173班_李宇泰  自动化发送邮件')
sleep(1)
iframe = driver.find_element_by_class_name('APP-editor-iframe')
driver.switch_to.frame(iframe)
driver.find_element_by_class_name('nui-scroll').send_keys('吃葡萄不吐葡萄皮！！！')
driver.switch_to.default_content()
driver.find_element_by_class_name('nui-ico-sent').click()
sleep(5)
# driver.quit()